﻿using System;
using System.Windows.Forms;
using YinLongTool.Serialize;

namespace YinLongTool.Config
{
    public class AppConfig<T> where T : AppConfig<T>, new()
    {
        //public AppConfig()
        //{

        //}
        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="path">配置文件路径,默认Application.StartupPath + "\\config.ini"</param>
        //public AppConfig(string path)
        //{
        //	AppConfig<T>.fileName = path;
        //}
        public static T Instance
        {
            get
            {
                if (AppConfig<T>.instance == null)
                {

                    AppConfig<T>.instance = XMLSerializer.XmlDeserialize<T>(AppConfig<T>.FileName);
                }
                return AppConfig<T>.instance;
            }
        }

        public void Save()
        {
            XMLSerializer.XmlSerialize(this, AppConfig<T>.FileName);
        }

        private static T instance;

        /// <summary>
        /// 文件存储路径
        /// </summary>
        public static string FileName { get; set; } = Application.StartupPath + "\\config.yl";
    }
}
